// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/*
 * @Author: qiulin 1746365080@qq.com
 * @Date: 2024-10-24 14:51:52
 * @LastEditors: qiulin_JXGM ql1746365080@gmail.com
 * @LastEditTime: 2024-12-06 19:58:31
 * @FilePath: /SGSim/DBManager/UnitTest/HDF5/Input/NodeTest.cpp
 */

#include <algorithm>
#include <exception>
#include <iostream>
#include <vector>

#include <gtest/gtest.h>

#include "DataStructure/Common/Id.h"
#include "DataStructure/Input/Node/NodeData.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Partition/ISET1Service.h"
#include "DBManager/UnitTest/HDF5/TestDB.h"

using namespace SG::DBManager;
using namespace SG::DataStructure::FEM;

class I_PartitionTest : public testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        if (DB::ServiceFactory != nullptr)
        {
            DB::ServiceFactory->ClearDatabase ();
        }
    }
};

TEST_F (I_PartitionTest, SET1Data)
{
    SG::DataStructure::Common::Id const id = 100;
    // 创建对象
    SET1Data obj;
    obj.m_id = id;

    for(int i = 0; i < 9; i++)
    {
        obj.m_gids.push_back(i);
    }

    // 获取服务
    auto service = DB::ServiceFactory->get<ISET1Service> ();
    // 添加对象
    service->Add (obj);

    SET1Data res;
    service->FindById(100, res);
    ASSERT_EQ (service->Size (), 1);
    ASSERT_EQ (res.m_id, 100);
    ASSERT_EQ (res.m_gids.size(), 9);

    for(int i = 0; i < 9; i++)
    {
        ASSERT_EQ (res.m_gids[i], i);
    }
}